package com.xu.crawler.remote;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.xu.crawler.config.timeWaitingStrategy.TimeWaitingStrategy;
import com.xu.crawler.config.timeWaitingStrategy.DefaultTimeWaitingStrategy;
import com.xu.crawler.util.HttpClientUtils;
import org.apache.http.Consts;
import org.apache.http.client.HttpClient;

import java.io.IOException;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

/**
 * Created by clear on 2018/7/10.
 */
public abstract class AbstractRemoteService extends UnicastRemoteObject {

    protected String webSite;

    protected TimeWaitingStrategy strategy;

    protected ObjectMapper mapper;

    static HttpClient httpClient = HttpClientUtils.createHttpClient(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);

    public String request(String url) throws IOException {
//        return new HttpRequestHelper(webSite).request(url);
        return HttpClientUtils.sendGet(httpClient, url, Consts.UTF_8);
    }

    public AbstractRemoteService(TimeWaitingStrategy strategy, String webSite) throws RemoteException {
        super();
        this.webSite = webSite;
        this.strategy = strategy == null ? new DefaultTimeWaitingStrategy() : strategy;
        this.mapper = new ObjectMapper();
    }
}
